<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 300px;
            height: 300px;
            margin: auto;
        }

        ul {
            width: 500px;
            height: 300px;
            border: 1px solid #ccc;
        }

        ul li {
            float: left;
            list-style: none;
            width: 100px;
            height: 100px;
            line-height: 100px;
            text-align: center;
        }
    </style>
</head>

<body>
    <div>
        <input type="button" value="变色">
        <ul>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
            <li>列表</li>
        </ul>
    </div>

</body>
<script>
    document.querySelector('input').onclick = function () {
        let liArr = document.getElementsByTagName('li');
        for (let i = 0; i < liArr.length; i++) {
            if (i % 2 == 0) {
                liArr[i].style.backgroundColor = '#fff';
            } else {
                liArr[i].style.backgroundColor = 'rgba(0,0,0,0.5)';
            }
        }
    }
</script>

</html>